<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="com.example.model.Post" %>
<!DOCTYPE html>
<html>
<head>
    <title>编辑博客</title>
    <style>
        body { font-family: Arial, sans-serif; margin: 20px; }
        .form-group { margin-bottom: 10px; }
        textarea { width: 100%; height: 200px; }
    </style>
</head>
<body>
    <% 
        Post post = (Post)request.getAttribute("post");
        boolean isEdit = post != null;
    %>
    <h1><%= isEdit ? "编辑博客" : "写新博客" %></h1>
    
    <form method="post" action="${pageContext.request.contextPath}/posts">
        <input type="hidden" name="action" value="<%= isEdit ? "update" : "create" %>">
        <% if (isEdit) { %>
            <input type="hidden" name="id" value="<%= post.getId() %>">
        <% } %>
        
        <div class="form-group">
            <label>标题：</label>
            <input type="text" name="title" value="<%= isEdit ? post.getTitle() : "" %>" required>
        </div>
        
        <div class="form-group">
            <label>内容：</label>
            <textarea name="content" required><%= isEdit ? post.getContent() : "" %></textarea>
        </div>
        
        <div class="form-group">
            <input type="submit" value="保存">
            <a href="${pageContext.request.contextPath}/posts">返回列表</a>
        </div>
    </form>
</body>
</html> 